package com.tms.quartz.job;

import com.tms.domain.Tool;
import com.tms.domain.User;
import com.tms.quartz.mail.thread.SimpleMailThread;
import com.tms.service.ToolService;
import com.tms.service.UserService;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

/**
 * 邮件发送任务
 *
 * @author jackie
 * @date 2020年6月30日
 */
public class MailJob extends QuartzJobBean {

    @Autowired
    ToolService toolService;

    @Autowired
    UserService userService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {

        JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();

        int toolId = Integer.parseInt(dataMap.getString("toolId"));

        Tool tool = toolService.findToolById(toolId);
        User owner = tool.getTDef().getOwner();

        System.out.println(new Date() + "任务开始------------------------------------");
        SimpleMailThread mailThread = new SimpleMailThread(owner.getEmail(), "夹具点检提醒", "n", tool);
        mailThread.run();
        System.out.println(new Date() + "任务结束------------------------------------");
    }
}

